package com.ruoyi.qsng.service.impl;

import com.ruoyi.common.utils.DateUtils;
import com.ruoyi.common.utils.uuid.SnowFlakeUtil;
import com.ruoyi.qsng.domain.KIntegralDetailed;
import com.ruoyi.qsng.mapper.KIntegralDetailedMapper;
import com.ruoyi.qsng.service.IKIntegralDetailedService;
import com.ruoyi.system.service.ISysDictDataService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 积分明细Service业务层处理
 *
 * @author kanglou
 * @date 2023-06-07
 */
@Service
public class KIntegralDetailedServiceImpl implements IKIntegralDetailedService {
    @Autowired
    private KIntegralDetailedMapper kIntegralDetailedMapper;
    @Autowired
    private ISysDictDataService iSysDictDataService;

    /**
     * 查询积分明细
     *
     * @param id 积分明细主键
     * @return 积分明细
     */
    @Override
    public KIntegralDetailed selectKIntegralDetailedById(String id) {
        return kIntegralDetailedMapper.selectKIntegralDetailedById(id);
    }

    /**
     * 查询积分明细列表
     *
     * @param kIntegralDetailed 积分明细
     * @return 积分明细
     */
    @Override
    public List<KIntegralDetailed> selectKIntegralDetailedListForApp(KIntegralDetailed kIntegralDetailed) {
        return kIntegralDetailedMapper.selectKIntegralDetailedListForApp(kIntegralDetailed);
    }

    /**
     * 查询积分明细列表
     *
     * @param kIntegralDetailed 积分明细
     * @return 积分明细
     */
    @Override
    public List<KIntegralDetailed> selectKIntegralDetailedList(KIntegralDetailed kIntegralDetailed) {
        return kIntegralDetailedMapper.selectKIntegralDetailedList(kIntegralDetailed);
    }

    /**
     * 查询积分明细列表(导出excel数据转换)
     *
     * @param kIntegralDetailed 积分明细
     * @return 积分明细集合
     */
    @Override
    public List<KIntegralDetailed> selectKIntegralDetailedListExport(KIntegralDetailed kIntegralDetailed) {
        List<KIntegralDetailed> list = kIntegralDetailedMapper.selectKIntegralDetailedList(kIntegralDetailed);
        if (null != list && list.size() > 0) {
            for (KIntegralDetailed kIntegralDetailedOne : list) {
                if (StringUtils.isNotEmpty(kIntegralDetailedOne.getType())) {
                    String dictLabel = iSysDictDataService.selectDictLabel("k_integral_detailed_type", kIntegralDetailedOne.getType());
                    kIntegralDetailedOne.setType(dictLabel);
                }
            }
        }
        return list;
    }

    /**
     * 新增积分明细
     *
     * @param kIntegralDetailed 积分明细
     * @return 结果
     */
    @Override
    public int insertKIntegralDetailed(KIntegralDetailed kIntegralDetailed) {
        kIntegralDetailed.setId(SnowFlakeUtil.getNextId());
        kIntegralDetailed.setCreateTime(DateUtils.getNowDate());
        return kIntegralDetailedMapper.insertKIntegralDetailed(kIntegralDetailed);
    }

    /**
     * 修改积分明细
     *
     * @param kIntegralDetailed 积分明细
     * @return 结果
     */
    @Override
    public int updateKIntegralDetailed(KIntegralDetailed kIntegralDetailed) {
        kIntegralDetailed.setUpdateTime(DateUtils.getNowDate());
        return kIntegralDetailedMapper.updateKIntegralDetailed(kIntegralDetailed);
    }

    /**
     * 批量删除积分明细
     *
     * @param ids 需要删除的积分明细主键
     * @return 结果
     */
    @Override
    public int deleteKIntegralDetailedByIds(String[] ids) {
        return kIntegralDetailedMapper.deleteKIntegralDetailedByIds(ids);
    }

    /**
     * 删除积分明细信息
     *
     * @param id 积分明细主键
     * @return 结果
     */
    @Override
    public int deleteKIntegralDetailedById(String id) {
        return kIntegralDetailedMapper.deleteKIntegralDetailedById(id);
    }
}
